<?php

namespace app\admin\controller\yunfood\order;

use app\admin\model\yunfood\SysUser;
use addons\yunfood\library\Backend;
use app\admin\model\yunfood\OrderInvoice as OrderInvoiceModel;

/**
 * 发票申请模块
 */
class Invoice extends Backend
{
    /**
     * @var OrderInvoiceModel
     */
    protected $model;

    // 联表查询，解决字段冲突
    protected $relationSearch = true;

    protected $shopField = 'shop_id';

    // 初始化
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new OrderInvoiceModel();

        $this->view->assign('yesOrNo', [1 => '是', 0 => '否']);

        $this->view->assign('typeList', $this->model::getTypeList());
        $this->assignconfig('typeList', $this->model::getTypeList());

        $this->view->assign('titleTypeList', $this->model::getTitleTypeList());
        $this->assignconfig('titleTypeList', $this->model::getTitleTypeList());

        $this->view->assign('statusList', $this->model::getStatusList());
        $this->assignconfig('statusList', $this->model::getStatusList());
    }

    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            // 查询门店
            $where = $this->getShopWhere($where, 'order_invoice.shop_id');
            $list = $this->model->with(['user_data'])
                ->field('order_invoice.*')
                ->join([SysUser::getTableName() => 'user'], 'user.id=order_invoice.user_id', 'LEFT')
                ->where($where)->order($sort, $order)->limit($offset, $limit)->paginate($limit);
            $result = array(
                'total' => $list->total(),
                'rows'  => $list->items(),
            );

            return json($result);
        }

        return $this->view->fetch();
    }

    public function add()
    {
        return;
    }

    public function multi($ids = null)
    {
        return;
    }

    public function recyclebin()
    {
        return;
    }

    public function destroy($ids = null)
    {
        return;
    }

    public function restore($ids = null)
    {
        return;
    }
}
